﻿<?php
// ----------------------------------------------------------------------------
//
//  File: poll_add.php   
//  Creation Date:  06/09/11
//  Last Modified:  06/09/11
//  Purpose: 添加投票
//
// ----------------------------------------------------------------------------
?>
<?php 
	require_once("action/sys_conf.inc");
	if(isset($_GET[id])){	
		$id = $_GET[id];
		$link_id = mysql_connect($DBHOST,$DBUSER,$DBPWD);
		mysql_select_db($DBNAME);
		mysql_query("SET NAMES 'utf8'");
		$sql = "select id,subject,startTime,endTime,pollType,description from extpollsubject where id='$id' order by id desc";
		$result = mysql_query($sql);
		if(!$result)
		{
		  exit;
		}else{
			$row = mysql_fetch_array($result);
			$subject = $row['subject'];
			$startTime = $row['startTime'];
			$endTime = $row['endTime'];
			$pollType = $row['pollType'];
			$description = $row['description'];
		}
	}
?>
	<link rel="stylesheet" type="text/css" href="css/JSCal2/jscal2.css" />
  <link rel="stylesheet" type="text/css" href="css/JSCal2/border-radius.css" />
  <link rel="stylesheet" type="text/css" href="css/JSCal2/gold/gold.css" />
	<script language="JavaScript" type="text/javascript" src="js/JSCal2/jscal2.js"></script>
	<script language="JavaScript" type="text/javascript" src="js/JSCal2/cn.js"></script>	
	<script language="JavaScript" type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
	<script language="javascript" type="text/javascript">
		 $(document).ready(function(){
        $("#pollOption").load("poll_option.php?sid=<?php echo $id ?>");
    });
    var ophref;
		function iframe(i,href){
			if($("#iframe"+i).is(':hidden')||ophref !== href || href.indexOf("poll_media_add.php?id")!==-1){
				$("#iframe"+i).show();
				ophref = href;
				$.ajax({
					 url: href,
					 success: function(data){
					 	$("#iframe"+i).html(data);
					 }
				});
			}else{
				$("#iframe"+i).hide();
			}
		}
		function delPoll(scope,idx){			
			$.ajax({
				url:	'action/del.php',
				data: "scope="+scope+"&idx="+idx,					
				success: function(){
					alert( "删除成功！" );
					$("#"+scope+"_"+idx).remove();
					if($("#table_"+scope+" tr:last-child").is(":first-child")){
						$("#table_"+scope).remove();
					}					 
				},
				error:	function(){
					alert( "删除失败！" );
				}
			});			
		}
	</script>
	</head>
<body>

<div id="admin_container" style="position:relative">
	<h1>添加投票</h1>
	<form action="action/pollAdd.php" method="post" enctype="multipart/form-data">
	<input type="hidden" name="poll[id]" value="<?php echo $id ?>" />
	<div class="from-row">
		<label class="required">投票主题：</label>
		<div class="content"><input type="text" name="poll[subject]" value="<?php echo $subject ?>" /></div>
	</div>
	<div class="from-row">
		<label class="required">投票开始时间：</label>
		<div class="content"><input type="text" name="poll[startTime]" id="poll_startTime"  value="<?php echo $startTime ?>"  size="17" /><img id="trigger_poll_startTime" style="cursor:pointer;vertical-align:middle" src="/poll/admin/images/date.png" alt="Date" /><script type="text/javascript"> 
    document.getElementById("trigger_poll_startTime").disabled = false;
    Calendar.setup({
      trigger    : "trigger_poll_startTime",
			dateFormat : "%Y-%m-%d %k:%M",
      inputField : "poll_startTime"
    });
  </script></div>
	</div>
	<div class="from-row">
		<label class="required">投票结束时间：</label>
		<div class="content"><input type="text" name="poll[endTime]" id="poll_endTime" value="<?php echo $endTime ?>" size="17" /><img id="trigger_poll_endTime" style="cursor:pointer;vertical-align:middle" src="/poll/admin/images/date.png" alt="Date" /><script type="text/javascript"> 
    document.getElementById("trigger_poll_endTime").disabled = false;
    Calendar.setup({
      trigger    : "trigger_poll_endTime",
			dateFormat : "%Y-%m-%d %k:%M",
      inputField : "poll_endTime"
    });
  </script></div>
	</div>
	<div class="from-row">
		<label class="required">投票类型：</label>
		<div class="content"><input type="radio" name="poll[pollType]" value="0" <?php if(!$pollType){ echo 'checked="checked"';} ?> />单选&emsp;&emsp;<input type="radio" name="poll[pollType]" value="1" <?php if($pollType){ echo 'checked="checked"';} ?>/>多选</div>
	</div>
	<div class="from-row">
		<label class="required">投票介绍：</label>
		<div class="content"><textarea cols="50" rows="10" name="poll[description]"><?php echo $description ?></textarea></div>
	</div>
	<div class="from-row">
		<label class="required">投票选项：</label>
		<div class="content">
		<?php if($id){ ?>
			<a href="poll_option_add.php?sid=<?php echo $id ?>" target="in" onClick="javascript:iframe(1,$(this).attr('href'));">添加选项</a>
			<span id="pollOption"></span>
			<?php }else{ ?>
			请先保存投票
			<?php } ?>
		</div>
	</div>
	<div class="from-row">
		<input name="submitPoll" type="submit" value="提交" />
		<input name="cancel" type="button" value="取消" onClick="javascript:window.location.href='poll_list.php';" />
	</div>
	</form>
</div>
<iframe name="in" style="display:none"></iframe>
<div id="iframe1"></div>
<div id="iframe2"></div>
<style type="text/css">
#iframe1{width:50%;height:100%;border:none;position:absolute;top:0;left:50%;display:none}
#iframe2{width:400px;height:400px;border:none;position:absolute;top:25%;left:25%;background:#fff;display:none}
</style>
